﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;

namespace Nox.Amuse
{
    public static class DispatcherExtensions
    {
        public static void InvokeLambda(this Dispatcher d, Action whatToDo)
        {
            if (!d.CheckAccess())
                d.Invoke(whatToDo);
            else
                whatToDo();
        }

        public static void InvokeLambda<T>(this Dispatcher d, Action<T> whatToDo, T parm)
        {
            if (!d.CheckAccess())
                d.Invoke(whatToDo, parm);
            else
                whatToDo(parm);
        }

        public static void InvokeLambda<T1, T2>(this Dispatcher d, Action<T1, T2> whatToDo, T1 parm1, T2 parm2)
        {
            if (!d.CheckAccess())
                d.BeginInvoke(whatToDo, parm1, parm2);
            else
                whatToDo(parm1, parm2);
        }

        public static void BeginInvokeLambda(this Dispatcher d, Action whatToDo, DispatcherPriority priority)
        {
            if (!d.CheckAccess())
                d.BeginInvoke(whatToDo, priority);
            else
                whatToDo();
        }

        public static void BeginInvokeLambda<T>(this Dispatcher d, Action<T> whatToDo, T parm, DispatcherPriority priority)
        {
            if (!d.CheckAccess())
                d.BeginInvoke(whatToDo, priority, parm);
            else
                whatToDo(parm);
        }

        public static void BeginInvokeLambda<T1, T2>(this Dispatcher d, Action<T1, T2> whatToDo, T1 parm1, T2 parm2, DispatcherPriority priority)
        {
            if (!d.CheckAccess())
                d.BeginInvoke(whatToDo, priority, parm1, parm2);
            else
                whatToDo(parm1, parm2);
        }

    }
}
